package com.rjwh.dingdong.client.util;

import android.content.Context;

import com.rjwh.dingdong.client.application.MyApplication;
import com.rjwh.dingdong.client.bean.localbean.LocalGmaeInfo;

import java.io.IOException;
import java.util.List;

/**
 * 项目名称：whrjwh-parent
 * 类描述：
 * 创建人：wby
 * 创建时间：2016/9/14 10:24
 * 修改人：wby
 * 修改时间：2016/9/14 10:24
 * 修改备注：
 *
 */
public class OTGInster {

    public static void initData(Context context){

        inserlLocal(18,1,"乌鸦反哺",
                "http://resource.whtdlx.com/upload/PictureBook/package/2016-09-12/20160912170801457.zip", "",
                "http://resource.whtdlx.com/upload/PictureBook/cover/180/15.png","20160912170803",15237120);


        inserlLocal(409,1,"六尺巷",
                "http://resource.whtdlx.com/upload/PictureBook/package/2016-09-12/20160912112259848.zip", "",
                "http://resource.whtdlx.com/upload/PictureBook/cover/180/03.png","20160912112302",21286912);

        inserlLocal(57,1,"猪八戒吃西瓜",
                "http://resource.whtdlx.com/upload/PictureBook/package/2016-09-12/20160912111706877.zip", "",
                "http://resource.whtdlx.com/upload/PictureBook/cover/180/17.png","20160912111709",15237120 );

        inserlLocal(680,2,"启蒙之岛",
                "http://resource.whtdlx.com/upload/mathgame/package/201609091726680.zip", "",
                "http://resource.whtdlx.com/upload/mathgame/coverimage/1.png","20160909172807",153325568);

        LogUtil.d("copy");
        CopyUtil copyUtil = new CopyUtil(context);
        try {
            copyUtil.assetsCopy("drwabook", FileUtils.getDrwabookDirDirectory());
            copyUtil.assetsCopy("game", FileUtils.getGameDirectory());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }



    public static void inserlLocal(int gameid, int type, String gameName, String url, String path, String pic, String version, long totalLength) {
        List<LocalGmaeInfo> dbGamelist = MyApplication.db
                .findAllByWhere(
                        LocalGmaeInfo.class,
                        "pid="+gameid);
        if (dbGamelist.isEmpty()) {
            LocalGmaeInfo gminfo = new LocalGmaeInfo();
            gminfo.setType(type);
            gminfo.setPid(gameid);
            gminfo.setPname(gameName);
            gminfo.setDownloadUrl(url);
            gminfo.setIsUpdate(0);
            gminfo.setPath(path);
            gminfo.setPic(pic);
            gminfo.setVersion(version);
            gminfo.setTotalLength(totalLength);
            MyApplication.db.save(gminfo);
            LogUtil.i("HTML", "保存本地game");
        }
    }
}
